package com.ity.teamanagement.service.Impl;

import com.ity.teamanagement.entity.outputResult.GradeProvinceNumber;
import com.ity.teamanagement.entity.outputResult.TeaGradeProvinceVo;
import com.ity.teamanagement.entity.outputResult.TeaRareNumberVo;
import com.ity.teamanagement.entity.outputResult.VarietyTeaTypeCount;
import com.ity.teamanagement.mapper.TeaVisualizeMapper;
import com.ity.teamanagement.service.HomeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;

/**
 * @author coderFu
 * @create 2021/6/2
 */
@Service
public class HomeServiceImpl implements HomeService {

    @Resource
    private TeaVisualizeMapper teaVisualizeMapper;


    @Override
    public List<TeaGradeProvinceVo> teaGradeBarChart() {
        List<TeaGradeProvinceVo> teaGradeProvinceVos = new ArrayList<>();
        List<String> provinces = teaVisualizeMapper.findAllProvince();
        if (provinces.size() == 0){
            return new ArrayList<>();
        }
        LinkedHashMap<String, TeaGradeProvinceVo> hashMap = new LinkedHashMap<>();
        for (String province : provinces) {
            TeaGradeProvinceVo teaGradeProvinceVo = new TeaGradeProvinceVo();
            teaGradeProvinceVo.setProvince(province);
            teaGradeProvinceVos.add(teaGradeProvinceVo);
            hashMap.put(province,teaGradeProvinceVo);
        }
        List<GradeProvinceNumber> countryNumbers = teaVisualizeMapper.findCountryGradeNumber(provinces);
        for (GradeProvinceNumber countryNumber : countryNumbers) {
            TeaGradeProvinceVo teaGradeProvinceVo = hashMap.get(countryNumber.getProvince());
            teaGradeProvinceVo.setNationalLevelCount(countryNumber.getGradeCount());
        }
        List<GradeProvinceNumber> provinceNumbers = teaVisualizeMapper.findProvinceNumber(provinces);
        for (GradeProvinceNumber provinceNumber : provinceNumbers) {
            TeaGradeProvinceVo teaGradeProvinceVo = hashMap.get(provinceNumber.getProvince());
            teaGradeProvinceVo.setProvinceLevelCount(provinceNumber.getGradeCount());
        }
        List<GradeProvinceNumber> otherNumbers = teaVisualizeMapper.findOtherNumber(provinces);

        for (GradeProvinceNumber provinceNumber : otherNumbers) {
            TeaGradeProvinceVo teaGradeProvinceVo = hashMap.get(provinceNumber.getProvince());
            teaGradeProvinceVo.setOtherLevelCount(provinceNumber.getGradeCount());
        }
        return teaGradeProvinceVos;
    }

    @Override
    public List<TeaRareNumberVo> teaRarePieChart() {
        List<String> provinces = teaVisualizeMapper.findAllProvince();
        if (provinces.size() == 0){
           return new ArrayList<>();
        }
        List<TeaRareNumberVo> teaRareNumberVos = teaVisualizeMapper.findRareNumber(provinces);
        return teaRareNumberVos;
    }

    @Override
    public VarietyTeaTypeCount findAllTeaTypeCount() {
        VarietyTeaTypeCount varietyTeaTypeCount = new VarietyTeaTypeCount();
        Long allTeaCount = teaVisualizeMapper.findAllTeaTypeCount();
        Long countryLevelTeaCount = teaVisualizeMapper.findAllCountryLevelTeaCount();
        Long provinceLevelTeaCount = teaVisualizeMapper.findAllProvinceTeaCount();
        Long allRareCount = teaVisualizeMapper.findAllRareTeaCount();
        varietyTeaTypeCount.setAllTeaTypeCount(allTeaCount);
        varietyTeaTypeCount.setCountryLevelTeaCount(countryLevelTeaCount);
        varietyTeaTypeCount.setProvinceLevelTeaCount(provinceLevelTeaCount);
        varietyTeaTypeCount.setRareTeaCount(allRareCount);
        return varietyTeaTypeCount;
    }


}
